package com.example.campusforumapi.service.impl;

import com.example.campusforumapi.dao.ActivityTagMapper;
import com.example.campusforumapi.dao.CategoryMapper;
import com.example.campusforumapi.entity.ActivityTag;
import com.example.campusforumapi.entity.Category;
import com.example.campusforumapi.service.ActivityTagService;
import com.example.campusforumapi.util.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityTagServiceImpl implements ActivityTagService {
    @Autowired
    private ActivityTagMapper activityTagMapper;
    @Override
    public PageResult getTagPage(Integer page, Integer pageSize) {
        //1.设置分页参数
        PageHelper.startPage(page,pageSize);
//        2.执行查询
        List<ActivityTag> ActivityTagList = activityTagMapper.list();
        Page<ActivityTag> p = (Page<ActivityTag>) ActivityTagList;
//        3.封装PageResult对象
        PageResult pageResult = new PageResult(p.getResult(),p.getTotal(),p.getPageSize(),p.getPageNum());
        return pageResult;
    }

    @Override
    public int delTag(List<Integer> ids) {
        return activityTagMapper.delTag(ids);
    }

    @Override
    public int findsameTagName(String tagName) {
        return activityTagMapper.findsameTagName(tagName);
    }

    @Override
    public int findsameTagId(Integer tagId) {
        return activityTagMapper.findsameTagId(tagId);
    }

    @Override
    public int insertTag(ActivityTag activityTag) {
        activityTag.setCreateTime(LocalDateTime.now());
        return activityTagMapper.insertTag(activityTag);
    }

    @Override
    public int updTag(ActivityTag activityTag) {
        activityTag.setUpdateTime(LocalDateTime.now());//更新修改时间
        return activityTagMapper.updTag(activityTag);
    }
}
